package cn.lili.modules.payment.entity.dos;

import cn.lili.mybatis.model.BaseEntity;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

/**
 * 支付补差
 *
 * @author Chopper
 * @since 2021/1/28 09:21
 */
@Data
@TableName("li_payment_subsidies")
@Builder
@ApiModel(value = "支付补差")
@NoArgsConstructor
@AllArgsConstructor
public class PaymentSubsidies extends BaseEntity {


    @ApiModelProperty(value = "付款人ID")
    private String payerId;

    @ApiModelProperty(value = "付款人名称")
    private String nickname;

    //收款人信息，如果是-1，则标识平台收款
    @ApiModelProperty(value = "收款人ID")
    private String payeeId;

    @ApiModelProperty(value = "订单编号")
    private String orderSn;

    @ApiModelProperty(value = "订单描述")
    private String description;

    /**
     * @see cn.lili.modules.payment.entity.enums.PaymentClientEnum
     */
    @ApiModelProperty(value = "订单来源")
    private String paymentClient;

    /**
     * @see cn.lili.modules.payment.entity.enums.PaymentMethodEnum
     */
    @ApiModelProperty(value = "支付方式")
    private String paymentMethod;

    @ApiModelProperty(value = "金额")
    private Double price;


    @ApiModelProperty(value = "第三方支付发起交易号")
    private String outTradeNo;

    @ApiModelProperty(value = "第三方平台付款流水号")
    private String transactionId;


    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @ApiModelProperty(value = "支付过期时间", hidden = true)
    private Date timeoutExpress;

    @CreatedDate
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(fill = FieldFill.INSERT)
    @ApiModelProperty(value = "创建时间", hidden = true)
    private Date createTime;


    //保留，以下内容暂时用不到，目前补差逻辑全部使用平台内部的余额支付
    @ApiModelProperty(value = "支付请求参数")
    private String paymentRequestSource;


    @ApiModelProperty(value = "支付响应")
    private String paymentResponseSource;

    @ApiModelProperty(value = "分账单号")
    private String outOrderNo;

    @ApiModelProperty(value = "分账详细")
    private String receivers;

    /**
     * 生成补差描述
     *
     * @param orderSn 订单号
     * @param amount  补差金额
     * @return 补差描述
     */
    public static String generateSubsidiesText(String orderSn, Double amount) {
        return String.format("订单[%s]补差,金额[%f]", orderSn, amount);
    }

}
